#pragma once

#include <vector>

using namespace std;

class CPEFile
{
public:
	CPEFile(void);
	virtual ~CPEFile(void);

	BOOL Open(const CString & strFileName);
	BOOL ParsePE();
	BOOL AddSection(LPCSTR strSectionName, LPVOID pvContent, 
		DWORD pvVirtualAddr, DWORD dwVirtualSize, 
		DWORD dwRawDataSize, DWORD dwRawDataOffset, 
		DWORD dwSectionFlag = IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE);
	BOOL Save(const CString & strFileName);

private:
	BOOL IsPEFile();

private:
	PVOID	m_pvMapAddr;
	int		m_nFileSize;
	PIMAGE_DOS_HEADER m_pDosHeader;
	PIMAGE_NT_HEADERS m_pNtHeader;
	PIMAGE_FILE_HEADER m_pFileHeader;
	PIMAGE_OPTIONAL_HEADER m_pOptionalHeader;
	int m_nSectionsNum;
	PIMAGE_SECTION_HEADER m_pSectionHeader;
};
